package com.hnhs.controller;

import com.hnhs.dto.ResponseDto;
import com.hnhs.exceptions.MyException;
import com.hnhs.model.Category;
import com.hnhs.model.CategoryQuery;
import com.hnhs.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/category")
//@CrossOrigin
public class CategoryController {
    @Autowired
    private CategoryService service;

    @GetMapping("/find")
    public List<Category> findAll(){
//        int a=1/0;
//        if(1==1){
//            throw new MyException(886,"报错了。。。");
//        }
        return  service.findAll();
    }

    @GetMapping
    public List<Category> select(CategoryQuery query){
        return service.select(query);
    }
//    @GetMapping
//    public ResponseDto select(CategoryQuery query){
//        List<Category> categoryList = service.select(query);
//
//        return ResponseDto.success(categoryList);
//    }

    @PostMapping
    public Integer insert(@RequestBody Category category){
        return  service.insert(category);
    }
    @PutMapping
    public Integer update(@RequestBody Category category){
        return  service.update(category);
    }
    @DeleteMapping
    public Integer delete(Integer id){
        return  service.delete(id);
    }
}
